package com.hs.car.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.car.pojo.Car;
import com.hs.car.mapper.CarMapper;
import com.hs.car.pojo.vo.CarVo;
import com.hs.car.service.ICarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 车辆信息 服务实现类
 * </p>
 *
 * @author Bai
 * @since 2022-07-20
 */
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {

    @Autowired
    private CarMapper carMapper;

    @Override
    public PageInfo<CarVo> queryByPage(Integer currentPage, Integer pageSize, String licensePlate, String plateType, String nickName) {

        licensePlate = StringUtils.hasText(licensePlate)?"'"+licensePlate+"'":"'"+"%"+"'";

        plateType = StringUtils.hasText(plateType)?"'"+plateType+"'":"'"+"%"+"'";

        nickName = StringUtils.hasText(nickName)?"'"+nickName+"'":"'"+"%"+"'";

        PageHelper.startPage(currentPage,pageSize);
        List<CarVo> carVos = carMapper.carListByPage(licensePlate, plateType, nickName);
        PageInfo<CarVo> carVoPageInfo = new PageInfo<>(carVos);
        return carVoPageInfo;
    }

}
